package agentFramework.strategy;

import agentFramework.action.Action;
import java.util.ArrayList;
import agentFramework.agent.*;
import agentFramework.core.env.Environment;
import agentFramework.utils.*;


public abstract class Strategy 
{
	protected Environment	 						environment;
	protected Agent									agent;				// the owner of the strategy
	protected ArrayList< Pair<Integer, Action> > 	agentDecisions; 	// to be used with Pair of AgentID and corresponding Action
	
	
	public Strategy(Environment env, Agent owner)
	{
		this.environment = env;
		this.agent = owner;
		this.agentDecisions = new ArrayList< Pair<Integer, Action> >();
	}
	
	
	public void updateAgentDecision(Integer agentId, Action action)
	{
		boolean found = false;
		
		for (Pair<Integer, Action> elem : agentDecisions)
		{
			if (elem.first.equals(agentId))
			{
				found = true;
				elem.second = action;
				break;
			}
		}
		
		if (!found)
		{
			agentDecisions.add(new Pair< Integer, Action >(new Integer(agentId.intValue()), action));
		}
	}
	
	// init the strategy
	// in this moment all the agents are in the environment so adding some default knowledge
	// about the neighbors can be done safely
	public abstract void init();
	
	public abstract Action makeDecision();
		
	public abstract void reviseStrategy();
}